package com.atguigu.ai.functioncall.service;

import com.fasterxml.jackson.annotation.JsonClassDescription;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyDescription;
import org.springframework.context.annotation.Description;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.function.Function;

@Service
@Description("时间查询服务 - 可以获取不同时区的当前时间信息")
@JsonClassDescription("时间查询服务")
public class TimeService implements Function<TimeService.Request, TimeService.Response> {

    @Override
    public Response apply(Request request) {
        String timezone = request.timezone() != null ? request.timezone() : "Asia/Shanghai";
        String format = request.format() != null ? request.format() : "yyyy-MM-dd HH:mm:ss";
        
        LocalDateTime now = LocalDateTime.now(ZoneId.of(timezone));
        String formattedTime = now.format(DateTimeFormatter.ofPattern(format));
        
        return new Response(timezone, format, formattedTime, now.toString());
    }

    @JsonInclude(JsonInclude.Include.NON_NULL)
    @JsonClassDescription("时间查询请求参数")
    public record Request(
            @JsonProperty(value = "timezone")
            @JsonPropertyDescription("时区，例如：Asia/Shanghai, America/New_York, Europe/London")
            String timezone,
            
            @JsonProperty(value = "format")
            @JsonPropertyDescription("时间格式，例如：yyyy-MM-dd HH:mm:ss, yyyy年MM月dd日 HH:mm")
            String format
    ) {}

    @JsonClassDescription("时间查询响应结果")
    public record Response(String timezone, String format, String formattedTime, String isoTime) {}
} 